package cn.edu.xmu.orderpayment.payment.util;


import cn.edu.xmu.orderpayment.payment.util.paypattern.BasePaymentPattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;

/**
 * @author zihan zhou
 * @date 2021/12/5
 */
@Component
public class PayMentPatternLoader {

    @Autowired
    private ApplicationContext applicationContext;

    public BasePaymentPattern getPaymentPatternByClassName(String paymentPatternClassName) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
        String front = "cn.edu.xmu.orderpayment.payment.util.paypattern.";
        String paymentPatternClassFullName = front + paymentPatternClassName;
        Class paymentPatternClass = Class.forName(paymentPatternClassFullName);
        return (BasePaymentPattern) applicationContext.getBean(paymentPatternClass);
    }


}
